/*
 * Copyright (c) 2020 hebeiyiliuba.com
 * All rights reserved.
 *
 */
package org.jeecg.modules.wlhy.report.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.enums.ReportPlatformEnum;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.third.jg.report.freight.information.constant.XinjiangReportConstant;
import org.jeecg.modules.third.jg.report.freight.information.constant.enums.ReportDocTypeEnum;
import org.jeecg.modules.third.jg.report.freight.information.dto.AppInfoDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.DriverDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.VehicleDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.financial.FinancialDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.financial.FinanciallistDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.shippingnote.ShippingNoteDTO;
import org.jeecg.modules.third.jg.report.freight.information.model.R;
import org.jeecg.modules.third.jg.report.freight.information.model.XinjiangReqModel;
import org.jeecg.modules.third.jg.report.freight.information.service.YunnanReportPlatformService;
import org.jeecg.modules.wlhy.bill.entity.HyShippingNoteBill;
import org.jeecg.modules.wlhy.bill.service.IHyShippingNoteBillService;
import org.jeecg.modules.wlhy.company.entity.HyCompanyConfig;
import org.jeecg.modules.wlhy.hydriver.entity.HyDriver;
import org.jeecg.modules.wlhy.hydriver.entity.HyDriverReport;
import org.jeecg.modules.wlhy.hydriver.service.IHyDriverReportService;
import org.jeecg.modules.wlhy.hydriver.service.IHyDriverService;
import org.jeecg.modules.wlhy.hyvehicle.entity.HyVehicle;
import org.jeecg.modules.wlhy.hyvehicle.entity.HyVehicleReport;
import org.jeecg.modules.wlhy.hyvehicle.entity.HyVehicleType;
import org.jeecg.modules.wlhy.hyvehicle.service.IHyVehicleReportService;
import org.jeecg.modules.wlhy.hyvehicle.service.IHyVehicleService;
import org.jeecg.modules.wlhy.report.IReportService;
import org.jeecg.modules.wlhy.shipping.constant.ShippingPayStatus;
import org.jeecg.modules.wlhy.shipping.entity.HyShippingNote;
import org.jeecg.modules.wlhy.shipping.service.IHyShippingNoteService;
import org.jeecg.modules.wlhy.utils.HyCfgUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;


@Service
@Slf4j
public class XinjiangReportService implements IReportService {

    @Resource
    private BaseReportService baseReportService;

    @Resource
    private IHyDriverService driverService;

    @Resource
    private IHyVehicleService vehicleService;

    @Autowired
    private IHyShippingNoteService hyShippingNoteService;

    @Autowired
    private IHyShippingNoteBillService hyShippingNoteBillService;

    @Resource
    private IHyDriverReportService hyDriverReportService;

    @Resource
    private IHyVehicleReportService hyVehicleReportService;

    //@Value(value= "${xj-report-platform.secretKey:f41e6475a5d6464a9ad1ea54ae987115}")
    private String secretKey;

    //新疆监管正式环境是1  默认测试环境是0
    //@Value(value= "${xj-report-platform.prod:0}")
    private String prod;

    //@Value(value="${xj-report-platform.appId:}")
    private String appId;

    //@Value(value="${xj-report-platform.appSecurity:}")
    private String appSecurity;

    //@Value(value="${xj-report-platform.appSenderCode:}")
    private String appSenderCode;

    //@Value(value="${xj-report-platform.appDebugSystem:}")
    private String appDebugSystem;

    @Override
    public ReportPlatformEnum getReportType() {
        return ReportPlatformEnum.REPORT_PLATFORM_XINJIANG;
    }

    @Override
    public void checkReport() {
        //新疆监管平台配置参数
        if(!HyCfgUtil.isUsed("xinjiang_report")){
            throw new JeecgBootException("新疆监管平台未配置参数!");
        }
    }

    @Override
    public AppInfoDTO getAppInfo() {
        return AppInfoDTO.builder()
                .appId(this.appId)
                .appSecurity(this.appSecurity)
                .enterpriseSenderCode(this.appSenderCode)
                .debugSystem(this.appDebugSystem)
                .build();
    }


    @Override
    public Result setReportInfo(HyCompanyConfig hyCompanyConfig) {

        if (StrUtil.isEmpty(hyCompanyConfig.getReportUrl()) || StrUtil.isEmpty(hyCompanyConfig.getReportPublickey())) {
            return Result.error("新疆监管平台未配置参数!");
        }

        //新疆监管正式环境是1  默认测试环境是0
        this.prod = "1";
        this.secretKey = hyCompanyConfig.getReportPublickey();
        this.appId = hyCompanyConfig.getReportAppid();
        this.appSecurity = hyCompanyConfig.getReportAppkey();
        this.appSenderCode = hyCompanyConfig.getReportAppsender();

        if ("0".equals(hyCompanyConfig.getReportApprelease())) {
            this.appDebugSystem = "debugSystem";
        }

        return Result.ok("设置成功");
    }

    @Override
    @Deprecated
    public boolean report(HyShippingNote hyShippingNote) {
        return false;
    }

    @Override
    public Result reportShippingNote(HyShippingNote hyShippingNote) {
        Result result = checkDriverAndVehicle(hyShippingNote);
        if (!result.getCode().equals(CommonConstant.SC_OK_200)) {
            return result;
        }

        return this.uploadShippingNote(hyShippingNote);
    }

    @Override
    public Result reportCapitalFlow(HyShippingNote hyShippingNote) {
        Result result = checkDriverAndVehicle(hyShippingNote);
        if (!result.getCode().equals(CommonConstant.SC_OK_200)) {
            return result;
        }

        return this.uploadCapitalFlow(hyShippingNote.getId());
    }

    //上报运单和资金流水前，先确认司机、车辆的上传状态
    private Result checkDriverAndVehicle(HyShippingNote hyShippingNote) {

        String driverId = hyShippingNote.getDriverId();
        String vehicleId = hyShippingNote.getVehicleId();
        if (StrUtil.isEmpty(driverId)) {
            return Result.error("当前运单司机信息不存在");
        }

        if (StrUtil.isEmpty(vehicleId)) {
            return Result.error("当前运单车辆信息不存在");
        }

        //自动上报司机和车辆配置
        String autoUpload = HyCfgUtil.getCfgItem2("xinjiang_report","auto_upload");
        boolean bDriverUploadStatus = this.hyDriverReportService.checkUploadStatus(driverId, hyShippingNote.getCompanyId(),
                ReportPlatformEnum.REPORT_PLATFORM_XINJIANG.getCode());
        if (!bDriverUploadStatus) {
            if (StrUtil.isEmpty(autoUpload) || !autoUpload.equals("1")) {
                return Result.error("请先同步司机数据");
            }
            log.warn("司机未上报新疆监管，开始同步司机数据, {}", driverId);
            Result dResult = this.reportDriver(driverId, hyShippingNote.getCompanyId());
            if (!dResult.getCode().equals(CommonConstant.SC_OK_200)) {
                return dResult;
            }
        }

        boolean bVehicleUploadStatus = this.hyVehicleReportService.checkUploadStatus(vehicleId, hyShippingNote.getCompanyId(),
                ReportPlatformEnum.REPORT_PLATFORM_XINJIANG.getCode());
        if (!bVehicleUploadStatus) {
            if (StrUtil.isEmpty(autoUpload) || !autoUpload.equals("1")) {
                return Result.error("请先同步车辆数据");
            }
            log.warn("车辆未上报新疆监管，开始同步车辆数据, {}", vehicleId);
            Result vResult = this.reportVehicle(vehicleId, hyShippingNote.getCompanyId());
            if (!vResult.getCode().equals(CommonConstant.SC_OK_200)) {
                return vResult;
            }
        }

        return Result.OK();
    }


    /**
     * 新疆上报资金流水
     *{
     * 	"dataType": "0",
     * 	"secretKey": "037b474b74df4f648fc54908d9c939ca",
     * 	"capitalStatementModel": {
     * 		"documentNumber": "456468546",
     * 		"sendToProDateTime": "20190819112233",
     * 		"carrier": "韩丽",
     * 		"actualCarrierId": "88910109881G566V32",
     * 		"vehicleNumber": "晋 AF3727",
     * 		"vehiclePlateColorCode": "1",
     * 		"shippingNoteList": [{
     * 				"shippingNoteNumber": "456123123132",
     * 				"serialNumber": "0101"
     *                        },
     *            {
     * 				"shippingNoteNumber": "456123123132",
     * 				"serialNumber": "0101"
     *            }
     * 		],
     * 		"financialList": [{
     * 				"paymentMeansCode": "42",
     * 				"recipient": "天顺",
     * 				"receiptAccount": "6217222806000169033",
     * 				"bankCode": "ZXBK",
     * 				"sequenceCode": "123456789987",
     * 				"monetaryAmount": 999.999,
     * 				"dateTime": "20190819112233"
     *            },
     *            {
     * 				"paymentMeansCode": "39",
     * 				"recipient": "天顺",
     * 				"receiptAccount": "6217222806000169033",
     * 				"bankCode": "ZXBK",
     * 				"sequenceCode": "123456789987",
     * 				"monetaryAmount": 777.777,
     * 				"dateTime": "20190819112233"
     *            }
     * 		]
     * 	}
     * }
     * @param shippingId
     * @return
     */
    public Result uploadCapitalFlow(String shippingId) {

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("shipping_id", shippingId);
        List<HyShippingNoteBill> shippingNoteBills = hyShippingNoteBillService.list(queryWrapper);

        if (CollectionUtils.isEmpty(shippingNoteBills)) {
            return Result.error("未找到对应数据");
        }

        try {

            HyShippingNote hyShippingNote = hyShippingNoteService.getById(shippingId);
            if (!hyShippingNote.getUploadStatus().equals("1")) {
                return Result.error("请先上报运单数据");
            }
            if (!hyShippingNote.getShippingPayStatus().equals(ShippingPayStatus.支付完成.getValue())) {
                return Result.error("该运单未支付完成");
            }

            FinancialDTO financialDTO = baseReportService.getFinancialDTO(shippingNoteBills,hyShippingNote);
//            //特殊处理，返回字段有Id和ID，只需要Id即可
//            financialDTO.setActualCarrierID(null);
            //新疆监管字段是大写的List，把小写list复制给大写字段
            JSONObject financialObj = JSONUtil.parseObj(financialDTO);
            financialObj.put("financialList",financialObj.get("financiallist"));
            financialObj.remove("financiallist");

            //准备报文
            XinjiangReqModel exchangeModel = XinjiangReqModel.builder()
                    .dataType(this.prod)
                    .secretKey(this.secretKey)
                    .capitalStatementModel(financialObj)
                    .build();

            log.info("新疆监管资金上报请求 -> {}", JSONUtil.toJsonStr(exchangeModel));
            String url = XinjiangReportConstant.DOMAIN_URL + XinjiangReportConstant.CAPITAL_URL;
            String result = HttpUtil.post(url, JSONUtil.toJsonStr(exchangeModel));
            log.info("新疆监管资金上报回执 <- {}", result);

            if (StrUtil.isEmpty(result)) {
                return Result.error("上报数据异常");
            }

            R r = JSONUtil.toBean(result, R.class, true);
            for (HyShippingNoteBill shippingNoteBillDb : shippingNoteBills) {
                //1成功 2失败
                shippingNoteBillDb.setUploadStatus((0 == r.getCode()) ? "1" : "2");
                shippingNoteBillDb.setUploadDate(new Date());
                shippingNoteBillDb.setReportFailureReason((0 == r.getCode()) ? "" : r.getMsg());
                shippingNoteBillDb.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_XINJIANG.getCode());
            }

            hyShippingNoteBillService.updateBatchById(shippingNoteBills);
            return (0 == r.getCode()) ? Result.OK("上报成功") : Result.error(r.getMsg());

        } catch (Exception e) {

            for(HyShippingNoteBill shippingNoteBillDb :  shippingNoteBills){
                shippingNoteBillDb.setUploadStatus("2");
                shippingNoteBillDb.setUploadDate(new Date());
                shippingNoteBillDb.setReportFailureReason(e.getMessage());
                shippingNoteBillDb.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_XINJIANG.getCode());
            }
            hyShippingNoteBillService.updateBatchById(shippingNoteBills);
            e.printStackTrace();
        }

        return Result.error("上报资金流水数据错误");
    }

    /**
     * 新疆上报电子运单
     * {
     *   "dataType": "0",
     *   "secretKey": "037b474b74df4f648fc54908d9c939ca",
     *   "waybillModel": {
     *     "originalDocumentNumber": "9999999999",
     * 	    "shippingNoteNumber": "4564s6af5d4f6s5",
     * 	    "vehicleAmount": 1,
     * 	    "serialNumber": "0103",
     * 	    "transportTypeCode": 1,
     * 	    "sendToProDateTime": "20190808112233",
     * 	    "carrier": "天地轮公司",
     * 	    "unifiedSocialCreditIdentifier": "99910109MA1G566Y32",
     * 	    "permitNumber": "510114118554",
     * 	    "consignmentDateTime": "20190808112233",
     * 	    "businessTypeCode": "1002996",
     * 	    "despatchActualDateTime": "20190808112233",
     * 	    "goodsReceiptDateTime": "20190808112233",
     * 	    "totalMonetaryAmount": "999.995",
     * 	    "consignorInfo": {
     * 		    "consignor": "张玉",
     * 		    "consignorId": "99910109MA1G566Y32",
     * 		    "placeOfLoading": "北京市朝阳区安华西里 8 号楼",
     * 		    "countrySubdivisionCode": "110105"
     *        },
     * 	    "consigneeInfo": {
     * 	    	"consignee": "张彦",
     * 	    	"consigneeId": "99910109991G566Y33",
     * 	    	"goodsReceiptPlace": "北京市朝阳区安华西里 88 号楼",
     * 	    	"countrySubdivisionCode": "110105"
     *        },
     * 	    "vehicleInfo": {
     * 	    	"vehiclePlateColorCode": "2",
     * 	    	"vehicleNumber": "京 AM618 挂",
     * 	    	"veDespatchActualDateTime": null,
     * 	    	"goodsReceiptDateTime": null,
     * 	    	"placeOfLoading": null,
     * 	    	"goodsReceiptPlace": null,
     * 	    	"loadingCountrySubdivisionCode": null,
     * 	    	"receiptCountrySubdivisionCode": null,
     * 	    	"driver": [{
     * 	    			"driverName": "李四",
     * 	    			"drivingLicense": "352229199010112099"
     *                },
     *                {
     * 	    			"driverName": "张三",
     * 	    			"drivingLicense": "652229199010112099"
     *                }
     * 	    	],
     * 	    	"goodsInfo": [{
     * 	    		"descriptionOfGoods": "管件",
     * 	    		"cargoTypeClassificationCode": "0600",
     * 	    		"goodsItemGrossWeight": 99000.999,
     * 	    		"cube": 10.000,
     * 	    		"totalNumberOfPackages": 1
     *            }]
     *        },
     * 	    "actualCarrierInfo": {
     * 	    	"actualCarrierName": "亨利",
     * 	    	"actualCarrierId": "88910109881G566V32",
     * 	    	"actualCarrierBusinessLicense": "88910109881G566V32"
     *        },
     * 	    "insuranceInformation": {
     * 	    	"policyNumber": "6000100000000000000",
     * 	    	"insuranceCompanyCode": "TKZX"
     *        },
     * 	    "remark": "示例"
     *       }
     * }
     */
    public Result uploadShippingNote(HyShippingNote hyShippingNote) {

        HyShippingNote ShippingNoteDb = hyShippingNoteService.getById(hyShippingNote.getId());
        if (null == ShippingNoteDb) {
            return Result.error("未找到对应数据");
        }
//        if("1".equals(ShippingNoteDb.getUploadStatus())){
//            return Result.OK();
//        }
            //查询车辆是否有轨迹
//            if(!"2".equals(hyShippingNote.getUploadStatus())) {
//                baseReportService.checkShippingNoteRoute(hyShippingNote);
//            }
        ShippingNoteDTO shippingNoteDTO = baseReportService.shippingNoteTOShippingNoteDTO(
                ShippingNoteDb, hyShippingNote.getCompanyId());

        //Added start at 2024-09-26 for 增加收发货地址经纬度
        if (null == hyShippingNote.getSendLongitude() || null == hyShippingNote.getSendLatitude()) {
            return Result.error("发货地址经纬度未设置");
        }
        if (null == hyShippingNote.getReceiveLongitude() || null == hyShippingNote.getReceiveLatitude()) {
            return Result.error("收货地址经纬度未设置");
        }
        shippingNoteDTO.getConsignorInfo().setLongitude(hyShippingNote.getSendLongitude().toString());
        shippingNoteDTO.getConsignorInfo().setLatitude(hyShippingNote.getSendLatitude().toString());
        shippingNoteDTO.getConsigneeInfo().setLongitude(hyShippingNote.getReceiveLongitude().toString());
        shippingNoteDTO.getConsigneeInfo().setLatitude(hyShippingNote.getReceiveLatitude().toString());
        //Added end at 2024-09-26 for 增加收发货地址经纬度

        //准备报文
        XinjiangReqModel exchangeModel = XinjiangReqModel.builder()
                .dataType(this.prod)
                .secretKey(this.secretKey)
                .waybillModel(shippingNoteDTO)
                .build();
        try{
            log.info("新疆监管运单上报请求 -> {}", JSONUtil.toJsonStr(exchangeModel));
            String url = XinjiangReportConstant.DOMAIN_URL + XinjiangReportConstant.SHIPPING_URL;
            String result = HttpUtil.post(url, JSONUtil.toJsonStr(exchangeModel));
            log.info("新疆监管运单上报回执 <- {}", result);

            R r = JSONUtil.toBean(result, R.class, true);
            if (0 == r.getCode()) {
                ShippingNoteDb.setUploadStatus("1");
            } else {
                ShippingNoteDb.setUploadStatus("2");
                ShippingNoteDb.setReportFailureReason(r.getMsg());
            }

            ShippingNoteDb.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_XINJIANG.getCode());
            ShippingNoteDb.setUploadDate(new Date());
            hyShippingNoteService.updateById(ShippingNoteDb);

            return (0 == r.getCode()) ? Result.OK("上报成功") : Result.error(r.getMsg());
        }catch (Exception e){
            e.printStackTrace();
        }

        return Result.error("运单数据上报错误");
    }

    /**
     *  车辆数据传输格式
     *  {
     *  	"dataType": "0",
     *  	"secretKey": "037b474b74df4f648fc54908d9c939ca",
     *  	"vehicleModel": {
     *  		"vehicleNumber": "鄂 FTC360",
     *  		"vehiclePlateColorCode": "2",
     *  		"vehicleType": "H11",
     *  		"owner": "深圳市神风运输有限公司",
     *  		"useCharacter": "道路普通货物运输",
     *  		"vin": "123456789",
     *  		"issuingOrganizations": "运管局",
     *  		"registerDate": "20191112",
     *  		"issueDate": "20191112",
     *  		"vehicleEnergyType": "A",
     *  		"vehicleTonnage": 21.30,
     *  		"grossMass": 9.90,
     *  		"roadTransportCertificateNumber": "420606208298"
     *  	}
     *  }
     * @param vehicleId
     * @return
     */
    @Override
    public Result reportVehicle(String vehicleId, String companyId) {

        HyVehicle hyVehiclDb = vehicleService.getById(vehicleId);
        if (null == hyVehiclDb) {
            return Result.error("未找到车辆信息");
        }

        if (StringUtils.isEmpty(hyVehiclDb.getRoadTransportNumber())) {
            return Result.error("车辆道路运输证不能为空！");
        }

        if (!vehicleService.checkRTCNoV2(hyVehiclDb)) {
            return Result.error("车辆道路运输证号不正确或者已过期，请修改后重新上传！");
        }

        HyVehicleType hyVehicleType = vehicleService.getHyVehicleType(hyVehiclDb.getVehicleType());
        if (null == hyVehicleType) {
            throw new JeecgBootException("车辆类型不存在,修改后请重新上报！");
        }

        hyVehiclDb.setVehicleType(hyVehicleType.getValue());
        VehicleDTO vehicleDTO = baseReportService.hyVehicleDTOTOVehicleDTO(hyVehiclDb);
        //准备报文
        XinjiangReqModel exchangeModel = XinjiangReqModel.builder()
                .dataType(this.prod)
                .secretKey(this.secretKey)
                .vehicleModel(vehicleDTO)
                .build();
        try {
            log.info("新疆监管车辆上报请求 -> {}", JSONUtil.toJsonStr(exchangeModel));
            String url = XinjiangReportConstant.DOMAIN_URL + XinjiangReportConstant.VEHICLE_URL;
            String result = HttpUtil.post(url, JSONUtil.toJsonStr(exchangeModel));
            log.info("新疆监管车辆上报回执 <- {}", result);
            R r = JSONUtil.toBean(result, R.class, true);
            boolean bUpdate = false;
            if (0 == r.getCode()) {
                //状态 1成功 2失败  0未上传
                bUpdate = this.vehicleService.updateJgUploadStatusById(vehicleId, "1");
            } else {
                bUpdate = this.vehicleService.updateJgUploadStatusById(vehicleId, "2");
            }

            HyVehicleReport hyVehicleReport = new HyVehicleReport();
            hyVehicleReport.setCompanyId(companyId);
            hyVehicleReport.setVehicleId(vehicleId);
            hyVehicleReport.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_XINJIANG.getCode());
            hyVehicleReport.setVehicleUploadStatus(0 == r.getCode() ? "1" : "2");
            hyVehicleReport.setUploadDate( new Date() );
            hyVehicleReport.setVehicleReportFailureReason(r.getMsg());
            hyVehicleReportService.saveVehicleReport(hyVehicleReport);

            log.info("新疆监管更新车辆上报回执信息, {}, {}", bUpdate, r.getMsg());
            return 0 == r.getCode() ? Result.OK("上报成功") : Result.error(r.getMsg());
        } catch (Exception e) {
            e.printStackTrace();
        }

        return Result.error("运单上报数据异常");
    }


    /**
     *  司机数据传输格式
     *  {
     *  	"dataType": "0",
     *  	"secretKey": "037b474b74df4f648fc54908d9c939ca",
     *  	"driverModel": {
     *  		"driverName": "蒋飞",
     *  		"drivingLicense": "342125197805990912",
     *  		"vehicleClass": "B2",
     *  		"issuingOrganizations": "运管局",
     *  		"validPeriodFrom": "20191112",
     *  		"validPeriodTo": "20191112",
     *  		"qualificationCertificate": "342125199805080912",
     *  		"telephone": "15869001655",
     *  		"remark": ""
     *  	}
     *  }
     * @param driverId
     * @return
     */
    @Override
    public Result reportDriver(String driverId, String companyId) {

        HyDriver hyDriverDb = driverService.getById(driverId);
        if (null == hyDriverDb) {
            return Result.error("未找到司机信息");
        }

        try {
            //人员从业资格证验证
            if (!driverService.checkQualificationV2(hyDriverDb)) {
                throw new JeecgBootException("人员从业资格证验证号不正确或者已过期，请修改后重新上传！");
            }

            DriverDTO driverDTO = baseReportService.hyDriverTODriverDTO(hyDriverDb);
            //准备报文
            XinjiangReqModel exchangeModel = XinjiangReqModel.builder()
                    .dataType(this.prod)
                    .secretKey(this.secretKey)
                    .driverModel(driverDTO)
                    .build();

            log.info("新疆监管司机上报请求 -> {}", JSONUtil.toJsonStr(exchangeModel));
            String url = XinjiangReportConstant.DOMAIN_URL + XinjiangReportConstant.DRIVER_URL;
            String result = HttpUtil.post(url, JSONUtil.toJsonStr(exchangeModel));
            log.info("新疆监管司机上报回执 <- {}", result);
            R r = JSONUtil.toBean(result, R.class, true);
            boolean bUpdate = false;
            if (0 == r.getCode()) {
                //状态 1成功 2失败  0未上传
                bUpdate = this.driverService.updateJgUploadStatusById(driverId, "1");
            } else {
                bUpdate = this.driverService.updateJgUploadStatusById(driverId, "2");
            }

            HyDriverReport hyDriverReport = new HyDriverReport();
            hyDriverReport.setCompanyId(companyId);
            hyDriverReport.setDriverId(driverId);
            hyDriverReport.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_XINJIANG.getCode());
            hyDriverReport.setDriverUploadStatus(0 == r.getCode() ? "1" : "2");
            hyDriverReport.setUploadDate( new Date() );
            hyDriverReport.setDriverReportFailureReason(r.getMsg());
            hyDriverReportService.saveDriverReport(hyDriverReport);

            log.info("新疆监管更新司机上报回执信息, {}, {}", bUpdate, r.getMsg());
            return 0 == r.getCode() ? Result.OK("上报成功") : Result.error(r.getMsg());
        } catch (Exception e) {
            e.printStackTrace();
        }

        return Result.error("上报数据异常");
    }

}
